<?php

namespace app\admin\controller;

use think\Db;

class Subject extends Base
{
    // 显示学科分类
    public function index(){
    	$this->assign('data',[]);
    	return $this->fetch();
    }
    // 学科列表接口
    public function list(){
    	$data=Db::table('sys_subject')->where(['status_id'=>1])->order('sort','desc')->select();
    	return json($data);
    }
    // 添加分类
    public function add(){
    	$data=$this->request->param();
    	// var_dump($data);die;
    	try {
    		$res=Db::table('sys_subject')->strict(false)->insert($data);
    	} catch (\Exception $e) {
    		// echo 1;die;
    		return json(['data'=>null,'msg'=>'参数错误','code'=>500]);
    	}
    	if($res) {
    		return json(['data'=>null,'msg'=>'添加成功','code'=>200]);
    	}else{
    		return json(['data'=>null,'msg'=>'参数错误','code'=>500]);
    	}
	}
	// 编辑
	public function update(int $id){
		$data=$this->request->param();
		$res=Db::table('sys_subject')->where('id',$id)->update($data);
    	if($res) {
    		return json(['data'=>null,'msg'=>'编辑成功','code'=>200]);
    	}else{
    		return json(['data'=>null,'msg'=>'参数错误','code'=>500]);
    	}
	}
	// 删除
	public function delete(int $id){
    	$res=Db::table('sys_subject')->where('id',$id)->delete();
    	if($res){
    		return json(['data'=>null,'msg'=>'删除成功','code'=>200]);
    	}else{
    		return json(['data'=>null,'msg'=>'参数错误','code'=>500]);
    	}
		
	}
}

  /*`id` bigint(20) NOT NULL COMMENT '主键',
  `subject_name` varchar(50) NOT NULL COMMENT '分类名称',
  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `edit_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间',
  `status_id` tinyint(3) unsigned NOT NULL DEFAULT '1' COMMENT '状态(1:正常，0:禁用)',
  `sort` int(11) NOT NULL DEFAULT '1' COMMENT '排序',*/
